package com.tuweiya.study.hibernate.compositeKey;

import javax.persistence.Embeddable;

//@Embeddable
public class AnimalPK implements java.io.Serializable{
    private int id ;
    private String name ;

    public AnimalPK(){}
    public AnimalPK(int id, String name) {
        this.id = id;
        this.name = name;
    }

    // 重写hashCode和equals，来去定其唯一性


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof AnimalPK)) return false;

        AnimalPK animalPK = (AnimalPK) o;

        if (id != animalPK.id) return false;
        return name != null ? name.equals(animalPK.name) : animalPK.name == null;
    }

    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + (name != null ? name.hashCode() : 0);
        return result;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
